package com.ruoyi.yuangong.service.impl;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.yuangong.domain.PaibanReturn;
import com.ruoyi.yuangong.domain.Paibangaunli;
import com.ruoyi.yuangong.domain.vUser;
import com.ruoyi.yuangong.mapper.PaibangaunliMapper;
import com.ruoyi.yuangong.service.IPaibangaunliService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * paibanService业务层处理
 *
 * @author ruoyi
 * @date 2023-11-08
 */
@Service
public class PaibangaunliServiceImpl implements IPaibangaunliService {
    @Autowired
    private PaibangaunliMapper paibangaunliMapper;

    @Autowired
    private ISysUserService userService;

    /**
     * 查询paiban
     *
     * @param id paiban主键
     * @return paiban
     */
    @Override
    public Paibangaunli selectPaibangaunliById (Integer id) {
        return paibangaunliMapper.selectPaibangaunliById(id);
    }

    /**
     * 查询paiban列表
     *
     * @param paibangaunli paiban
     * @return paiban
     */
    @Override
    public List<Paibangaunli> selectPaibangaunliList (Paibangaunli paibangaunli) {
        return paibangaunliMapper.selectPaibangaunliList(paibangaunli);
    }

    /**
     * 新增paiban
     *
     * @param paibangaunli paiban
     * @return 结果
     */
    @Override
    public int insertPaibangaunli (Paibangaunli paibangaunli) {
        return paibangaunliMapper.insertPaibangaunli(paibangaunli);
    }

    /**
     * 修改paiban
     *
     * @param paibangaunli paiban
     * @return 结果
     */
    @Override
    public int updatePaibangaunli (Paibangaunli paibangaunli) {
        return paibangaunliMapper.updatePaibangaunli(paibangaunli);
    }

    /**
     * 批量删除paiban
     *
     * @param ids 需要删除的paiban主键
     * @return 结果
     */
    @Override
    public int deletePaibangaunliByIds (String ids) {
        return paibangaunliMapper.deletePaibangaunliByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除paiban信息
     *
     * @param id paiban主键
     * @return 结果
     */
    @Override
    public int deletePaibangaunliById (Integer id) {
        return paibangaunliMapper.deletePaibangaunliById(id);
    }

    @Override
    public vUser selectVUserById(Long userId) {
        return paibangaunliMapper.selectVUserById(userId);
    }

    @Override
    public PaibanReturn selectPaibanReturnById(Integer id) {
        Paibangaunli paibangaunli =  paibangaunliMapper.selectPaibangaunliById(id);
        SysUser user = userService.selectUserById(Long.valueOf(paibangaunli.getUserid()));
        PaibanReturn paibanReturn = new PaibanReturn();
        BeanUtils.copyProperties(paibangaunli,paibanReturn);
        paibanReturn.setUsername(user.getUserName());
        return paibanReturn;
    }
}
